package com.liehacker.android.mapservice;

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.liehacker.android.R;

public class C24_OverlayMulti extends MapActivity{
	
	MapView mMapView;
	Drawable mBlue, mRed;
	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}
	
	public void onCreate(Bundle saveInstances) {
		super.onCreate(saveInstances);
		setContentView(R.layout.c24_mapview);
		
		mMapView = (MapView)findViewById(R.id.c24_mapview);
		MapController mapControl = mMapView.getController();
		mapControl.setZoom(16);
		mMapView.setBuiltInZoomControls(true);
		
		GeoPoint gp = new GeoPoint(37497900, 127027700);
		mapControl.setCenter(gp);
		
		mBlue = getResources().getDrawable(R.drawable.bluemarker);
		mBlue.setBounds(0,0, mBlue.getIntrinsicWidth(), mBlue.getIntrinsicHeight());
		mRed = getResources().getDrawable(R.drawable.redmarker);
		mRed.setBounds(0,0, mRed.getIntrinsicWidth(), mRed.getIntrinsicHeight());
		
		Restaurant rest = new Restaurant(mBlue);
		List<Overlay> overlays = mMapView.getOverlays();
		overlays.add(rest);		
		
	}
	
	class Restaurant extends ItemizedOverlay<OverlayItem>{
		public Restaurant(Drawable defaultMaker) {
			super(defaultMaker);
			boundCenterBottom(defaultMaker);
			boundCenter(mRed);
			populate();
		}
		
		@Override
		protected OverlayItem createItem(int i) {
			OverlayItem item = null;
			
			switch(i) {
			case 0:
				item = new OverlayItem(new GeoPoint(37497000, 127031100), "할매칼국수","바지락 전문");
				break;
			case 1:
				item = new OverlayItem(new GeoPoint(37503000, 127029200), "강남떡복기","물은 셀프");
				break;
			}

			return item;
		}

		@Override
		public int size() {
			// TODO Auto-generated method stub
			return 2;
		}
		
		public boolean onTab(int index)  {
			String msg;
			OverlayItem item = getItem(index);
			msg = "상호 = " + item.getTitle() + " , 설명 = " + item.getSnippet();
			Toast.makeText(C24_OverlayMulti.this, msg, Toast.LENGTH_SHORT).show();
			return true;
		}
	}
	
}
